package main

import (
	"log"
	"time"
)

func stopTimer(t *time.Timer) {
	t.Stop()
	select {
	case <-t.C:
	default:
	}
}

func main() {
	ch := make(chan int)
	log.Println("start")
	timerWait := time.Second * 2
	t := time.NewTimer(timerWait)
	go func() {
		time.Sleep(1 * time.Hour)
		ch <- 1

	}()
	for {
		select {
		case <-t.C:
			log.Println("wake up ...")
			t.Stop()
			log.Println("stop timer ...")
		case <-ch:
			log.Println("chan can read")
		}
	}
}

// 如果去掉go func()的逻辑，则会报dead lock的错误，是因为没有管道可以读了
